package com.zscat.mallplus.center.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zscat.mallplus.annotation.IgnoreAuth;
import com.zscat.mallplus.annotation.SysLog;
import com.zscat.mallplus.center.BaseController;
import com.zscat.mallplus.center.entity.CenterColumnsRecommend;
import com.zscat.mallplus.center.service.ICenterColumnsRecommendService;
import com.zscat.mallplus.cms.entity.CmsSubject;
import com.zscat.mallplus.cms.service.ICmsSubjectService;
import com.zscat.mallplus.pms.entity.PmsProduct;
import com.zscat.mallplus.pms.entity.PmsProductCategory;
import com.zscat.mallplus.pms.service.IPmsProductCategoryService;
import com.zscat.mallplus.pms.service.IPmsProductService;
import com.zscat.mallplus.sms.service.ISmsHomeAdvertiseService;
import com.zscat.mallplus.utils.CommonResult;

import io.swagger.annotations.ApiOperation;

/**
 * 栏目推荐Controller
 * 
 * @author Wsen
 * @date 2020-10-03
 */
@RestController
@RequestMapping("/centers/recommend")
public class CenterColumnsRecommendController extends BaseController {
	
	@Resource
	private ICenterColumnsRecommendService centerColumnsRecommendService;
	
    @Resource
    private ICmsSubjectService subjectService;
    
    @Resource
    private IPmsProductCategoryService productCategoryService;
    @Resource
    private IPmsProductService productService;

	/**
	 * 查询栏目推荐列表
	 */
//    @PreAuthorize("@ss.hasPermi('centers:recommend:list')")
	@GetMapping("/list")
	public Object list(CenterColumnsRecommend centerColumnsRecommend) {
		List<CenterColumnsRecommend> list = centerColumnsRecommendService
				.selectCenterColumnsRecommendList(centerColumnsRecommend);
//		if(centerColumnsRecommend.getStoreId() == 1) {
//			list.get(0).setRecommendId(subjectService.getOne(new QueryWrapper<CmsSubject>().orderByDesc("create_time")).getId()+"");
//			list.get(1).setRecommendId();
//		}
		return new CommonResult().success(list);
	}

	/**
	 * 获取栏目推荐详细信息
	 */
//    @PreAuthorize("@ss.hasPermi('centers:recommend:query')")
	@GetMapping(value = "/{id}")
	public Object getInfo(@PathVariable("id") Long id) {
		return new CommonResult().success(centerColumnsRecommendService.selectCenterColumnsRecommendById(id));
	}

	
	/**
	 * 首页今日科普
	 */
    @SysLog(MODULE = "pms", REMARK = "查询首页推荐文章")
    @IgnoreAuth
    @ApiOperation(value = "查询首页推荐文章")
    @GetMapping(value = "/recommendSubjectList/list")
    public Object getRecommendSubjectList(Long id) {
        return new CommonResult().success(subjectService.getById(id));
    }
    
	/**
	 * 首页精品课程、玩酷好物
	 */
    @IgnoreAuth
    @ApiOperation(value = "精品课程")
    @SysLog(MODULE = "product", REMARK = "精品课程")
    @GetMapping(value = "courseList")
    public Object courseList(String ids) {
    	ArrayList<PmsProduct> list = new ArrayList<PmsProduct>();
        String[] split = ids.split(";");
        for (String str : split) {
			PmsProduct byId = productService.getById(Long.valueOf(str));
			if (byId != null) {
				list.add(byId);
			}
		}
        return new CommonResult().success(list);
    }
    
    
}
